package com.laf.mall.api.repository;

import com.laf.mall.api.dto.Reward;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author ygl
 * @create 2018-12-24
 * @DESCRIPTION
 **/
@Repository
public class RewardRepository {

    @Autowired
    JdbcTemplate jdbcTemplate;

    public Reward getValidCouponByRegister() {
        final String sql = "select * from `T_REWARD` where reward_id=? and reward_type=? ";

        return jdbcTemplate.queryForObject(sql, new Object[] {8,1},
                (rs, rowNum) -> {
                    Reward reward = new Reward();
                    reward.setReward_id(rs.getInt("reward_id"));
                    reward.setReward_type(rs.getInt("reward_type"));
                    reward.setReward_value(rs.getInt("reward_value"));
                    reward.setReward_start(rs.getString("reward_start"));
                    reward.setReward_end(rs.getString("reward_end"));

                    return reward;
                });
    }
}
